//
//  GQHShipperInfoView.m
//  Xanthium
//
//  Created by GuanQinghao on 06/03/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHShipperInfoView.h"
#import "GQHHeader.h"
#import "GQHCustomCell.h"

@interface GQHShipperInfoView () <UITableViewDelegate,UITableViewDataSource>


@end

@implementation GQHShipperInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self loadLocalData];
        [self loadUserInterface];
    }
    return self;
}

#pragma mark --Data
- (void)loadLocalData {
    
}

#pragma mark --View
- (void)loadUserInterface {
    
    CGRect frame = CGRectMake(0, self.qh_statusBarHeight + self.qh_navigationBarHeight, self.qh_contentAreaWidth, self.qh_contentAreaHeight + self.qh_tabBarHeight);
    UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = kWhiteColor;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.showsVerticalScrollIndicator = NO;
    if (@available(iOS 11.0, *)) {
        
        tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    [self addSubview:tableView];
}

#pragma mark --Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (0 == section) {
        
        return 1;
    } else if (1 == section) {
        
        return 5;
    } else if (2 == section) {
        
        return 3;
    } else {
        
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (0 == indexPath.section) {
        
        return 80.0f;
    } else if (1 == indexPath.section) {
        
        return 80.0f;
    } else if (2 == indexPath.section) {
        
        return 110.0f;
    } else {
        
        return CGFLOAT_MIN;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (0 == indexPath.section) {
        
        static NSString *identifier = @"aCell";
        GQHFollowedCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            
            cell = [[GQHFollowedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.userInteractionEnabled = NO;
        }
        
        return cell;
    } else if (1 == indexPath.section) {
        
        static NSString *identifier = @"bCell";
        GQHFreightCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            
            cell = [[GQHFreightCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.qh_routeLabel.font = kBiggerFont;
            cell.qh_contentLabel.font = kSmallerFont;
            cell.qh_timeLabel.font = kSmallerFont;
            cell.qh_pushButton.hidden = YES;
        }
        
        return cell;
    } else if (2 == indexPath.section) {
        
        static NSString *identifier = @"cCell";
        GQHReviewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            
            cell = [[GQHReviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.userInteractionEnabled = NO;
        }
        
        return cell;
    } else {
        
        return [UITableViewCell new];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (0 != section) {
        
        return 50.0f;
    }
    
    return CGFLOAT_MIN;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = kLightGrayColor;
    
    if (1 == section) {
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"他的货源(135)";
        titleLabel.textAlignment = NSTextAlignmentLeft;
        [headerView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.and.left.and.height.mas_equalTo(20);
            make.right.mas_equalTo(headerView.mas_centerX);
        }];
        
        UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [moreButton setTitleColor:kAppGreenColor forState:UIControlStateNormal];
        [moreButton setTitle:@"更多>>" forState:UIControlStateNormal];
        [headerView addSubview:moreButton];
        [moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.top.and.height.mas_equalTo(20);
            make.right.mas_equalTo(headerView);
            make.width.mas_equalTo(80);
        }];
        
    } else if (2 == section) {
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"评价信息(13)";
        titleLabel.textAlignment = NSTextAlignmentLeft;
        [headerView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.and.left.and.height.mas_equalTo(20);
            make.right.mas_equalTo(headerView.mas_centerX);
        }];
        
        UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [moreButton setTitleColor:kAppGreenColor forState:UIControlStateNormal];
        [moreButton setTitle:@"更多>>" forState:UIControlStateNormal];
        [headerView addSubview:moreButton];
        [moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.and.height.mas_equalTo(20);
            make.right.mas_equalTo(headerView);
            make.width.mas_equalTo(80);
        }];
    } else {
        
    }
    
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return [UIView new];
}

@end
